package cn.aposoft.mq.kafka.algorithms;

import org.apache.kafka.common.utils.ByteUtils;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class WriteVariantSize {

    public static void main(String[] args) throws IOException {
        int value = 0b0000_0010;
        ByteArrayOutputStream outputArray = new ByteArrayOutputStream();
        DataOutputStream outputStream = new DataOutputStream(outputArray);
        ByteUtils.writeVarint(value, outputStream);
        System.out.println(value);
        System.out.println((value << 1) ^ (value >> 31));

        byte[] bytes = outputArray.toByteArray();
        System.out.println("length:" + bytes.length);
        System.out.println(Arrays.toString(bytes));

        System.out.println(ByteUtils.sizeOfVarint(-1));
    }
}
